package vashion.azeroth.core.service.tran.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import vashion.azeroth.contant.GenericErrorEnum;
import vashion.azeroth.core.manager.personal.tran.PersonalReturnGoodsOrderManager;
import vashion.azeroth.core.personal.tran.pojo.PersonalReturnGoodsOrder;
import vashion.azeroth.core.result.ApiResult;
import vashion.azeroth.core.service.base.BaseService;
import vashion.azeroth.core.service.tran.PersonalReturnGoodsOrderService;

@Service
public class PersonalReturnGoodsOrderServiceImpl extends BaseService implements	PersonalReturnGoodsOrderService<PersonalReturnGoodsOrder> {
	
	private final static Logger log = LoggerFactory.getLogger(PersonalReturnGoodsOrderServiceImpl.class);

	@Autowired
	private PersonalReturnGoodsOrderManager returnGoodsOrderManager;

	@Override
	public ApiResult<List<PersonalReturnGoodsOrder>> getReturnGoodsOrderList(PersonalReturnGoodsOrder returnGoodsOrder) {
		ApiResult<List<PersonalReturnGoodsOrder>> result = new ApiResult<List<PersonalReturnGoodsOrder>>();
		
		int totalCount = returnGoodsOrderManager.findCnt(returnGoodsOrder);
		initPages(returnGoodsOrder, totalCount);
		List<PersonalReturnGoodsOrder> returnGoodsOrderList = returnGoodsOrderManager.find(returnGoodsOrder);
		
		result.setData(returnGoodsOrderList);
		result.setTotalCount(totalCount);
		
		return result;
	}

	@Override
	public ApiResult<Boolean> modifyReturnGoodsOrder(PersonalReturnGoodsOrder returnGoodsOrder) {
		
		int count = returnGoodsOrderManager.update(returnGoodsOrder);
		
		if(count > 0) {
			return ApiResult.newSuccessResult();
		}
		
		log.error("修改失败,退货订单号：" + returnGoodsOrder.getReturnGoodsNo());
		return ApiResult.newErrorResult(GenericErrorEnum.UPDATE_ERROR.getErrorCode(), GenericErrorEnum.UPDATE_ERROR.getErrorMessage());
	}
	
	
}
